﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UIBase;
using MFTool;
using MF_Base.Model;
using System.ComponentModel.Composition;
using System.Linq.Expressions;
using AutoUI.Areas.ConfigUI.Controllers;

namespace AutoUI.Areas.Sys.Controllers
{
    [Export]
    public class SelectorController : BaseController
    {
        public ActionResult List()
        {
            return View();
        }

        public JsonResult GetList()
        {
            string sql = "select Name, UICode from ListConfig";
            var tb = SqlHelper.CreateSqlHelper(EnumConn.MF_Base.ToString()).ExcuteTable(sql);
            var resDicList = tb.ToDicList();
            string defaultJson = DefaultValue.GetPopupSelector();

            foreach (var dic in resDicList)
            {
                dic.SetValue("From", "配置");
                dic.SetValue("Url", "/AutoUI/ConfigUI/List/PageView?UICode={0}".ReplaceArg(dic.GetValue("UICode")));
            }
            if (!string.IsNullOrEmpty(defaultJson))
            {
                var defaultDicList = defaultJson.JsonToDictionaryList();
                foreach (var defaultDic in defaultDicList)
                {
                    defaultDic.SetValue("From", "系统");
                }
                resDicList.AddRange(defaultDicList);
            }
            return Json(resDicList);
        }
    }
}